<?php
session_start();
//session_register('login_state');
//$_SESSION['login_state'] ;
?>

<?

//===========================================================
$path = '../';
include($path."common.php");
include($path."prod_fun.php");
//=========================================================== 
$pageout = "staff_login.php" ; 
if($_SESSION['login_state'] <> "S"){

	gotopage($pageout) ;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../css/cart.css" />
<script language="javascript">




var xmlHttp;
function createXHR(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (!xmlHttp) {
		alert('您使用的瀏覽器不支援 XMLHTTP 物件');
		return false;
	}
}

function sendRequest(url){
	createXHR() ;
	xmlHttp.open('GET',url,true) ;
	xmlHttp.onreadystatechange = catchXML ;
	xmlHttp.send(null) ;
}

function catchXML(){
	if (xmlHttp.readyState==4){
		xml=xmlHttp.responseXML;
		if (xmlHttp.status == 200) {
//            document.getElementById('s').innerHTML=xmlHttp.responseText ;
			location.reload() ;
		}else{
			alert('執行錯誤,代碼:'+xmlHttp.status+'\('+xmlHttp.statusText+'\)');
		}
	}
}



</script>
<?
//echo $_SESSION['login_state'] ;
$sql = "select * from kart_manage order by user_id " ;
$result = mysql_query($sql);

$site = "staff_list.php" ;
$pagesize = 20; //每頁筆數
$numrows = mysql_num_rows($result) ; //總筆數
$totalpages = ceil($numrows / $pagesize); //頁數、最後一頁頁碼
if(!isset($_GET["page"])){
$currentpage = 1 ;
}else{
$currentpage = $_GET['page'] ;
}
$startnum = ($currentpage -1) * $pagesize;   //開始的筆數
$startnum = $startnum < 0 ? 0 : $startnum;

$nowpage = $_GET['page'] ;
//===========================================================
echo "<form method=post id=frm_list name=frm_list action=\"staff_act.php?nowpage=$nowpage\">" ;
echo "<table width=800 border=1 align=center>" ;

echo "<tr>" ;
echo "<td align=left colspan=5><input name=action type=submit value='新增資料'>" ;
echo "</td>" ;
echo "<td align=right><input name=action type=submit value='登出'>" ;
echo "</td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td width=10% align=center>使用者編號</td>" ;
echo "<td width=20% align=center>使用者姓名</td>" ;
echo "<td width=20% align=center>權限</td>" ;
echo "<td width=10% align=center>權限開放</td>" ;
echo "<td width=5% align=center>編輯</td>" ;
echo "<td width=5% align=center>刪除</td>" ;
echo "</tr>" ;
//===========================================================
$act_up = urlencode("修改資料") ;
$act_del = urlencode("刪除") ;

$sql_list = "select * from kart_manage order by user_id limit $startnum,$pagesize" ;
$result_list = mysql_query($sql_list);
while($row_list=mysql_fetch_object($result_list)){
$staff_no = $row_list->user_id ;
$staff_name = $row_list->user_name ;
$staff_auth = $row_list->user_auth ;
$staff_valid = $row_list->user_valid ;

switch ($staff_auth){
	case "S":
		$auth_name = "系統管理員" ;
		break;
	case "P":
		$auth_name = "商品管理員" ;
		break;
	case "O":
		$auth_name = "訂單管理員" ;
		break;
}

if($staff_valid == "Y"){
	$valid = "啟用" ;
}else{
	$valid = "關閉" ; 
}

echo "<tr height=20>" ;
echo "<td align=center>".$staff_no."</td>" ;
echo "<td>".$staff_name."</td>" ;
echo "<td align=center>".$auth_name."</td>" ;
echo "<td align=center>".$valid."</td>" ;

echo "<td align=center>"."<input name=action type=button value='修改資料' onclick=\"location.href='staff_act.php?action=$act_up&pid=$staff_no&nowpage=$currentpage'\">"."</td>" ;
echo "<td align=center>"."<input name=action type=button value='刪除資料' onclick=\"if(!confirm('確定刪除？')){return false;};sendRequest('staff_act.php?action=$act_del&pid=$staff_no&ts='+new Date().getTime());\">"."</td>" ;

echo "</tr>" ;
}
//===========================================================
echo "</table>" ;
echo "</form>" ;
//===========================================================
echo "<table width=100% border=0 align=center>" ;
echo "<tr><td align=center>" ;
fenye($site,$currentpage,$totalpages) ;
echo "</td></tr>" ;
echo "</table>" ;
//===========================================================
?>
